'   P r o g r a m   n a m e :   M M 3 D _ M B 5 0 0 _ 0 1 . t x t                                                               1 4   M a r   2 0 2 1 
 
 '                 A u t o r :   l e o n a r d o   D E   P A L O 
 
 '       B e g i n   d a t e :   2 7   M a r   2 0 2 1 
 
 
 
 '   = = = = = = = = = =   V A R I A B L E   A S S I G N E M E N T   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 '   v 1   t o   J o y s t i c k 
 
 '   v 2   t o   J o y s t i c k 
 
 '   v 3   t o   J o y s t i c k 
 
 '   v 4   t o   W o r k i n g   l o o p 
 
 '   v 5   t o   W o r k i n g   l o o p 
 
 
 
 '   = = = = = = = = = = =   H A R D W A R E   S E T   U P   A T   T H E   E N D   O F   T H E   L I S T I N G   = = = = = = = = = = = = = = = 
 
 
 
 
 
 
 
 L o a d   M B 5 0 0 _ e a r l y . j p g 
 
 
 
 ' S p e e d   9 
 
 B u t t o n   1   T e x t   H o m e A l l 
 
 B u t t o n   2   T e x t   H o m e _ X 
 
 B u t t o n   3   T e x t   H o m e _ Y 
 
 B u t t o n   4   T e x t   H o m e _ Z 
 
 ' B u t t o n   5   T e x t   J o y 
 
 ' B u t t o n   6   T e x t   M o n e y P l a y 
 
 ' B u t t o n   7   T e x t   P u m p 
 
 ' B u t t o n   8   T e x t   D i s a b l e M o t o r 
 
 
 
 L o a d   T h e r e m i n o _ H A L \ T h e r e m i n o _ H A L . e x e 
 
 L o a d   T h e r e m i n o _ H A L \ t h e r e m i n o _ S l o t V i e w e r . e x e 
 
 " 
 
 ' L o a d   T h e r e m i n o _ H A L \ t h e r e m i n o _ G a m e p a d . e x e 
 
 
 
 
 
 ' K e y   5   	 	 	 G o s u b   F a r F o m Z e r o 
 
 K e y   R i g h t 	 	 G o s u b   M o v e R i g h t M 0 
 
 K e y   L e f t   	 	 G o s u b   M o v e L e f t M 0 
 
 K e y   U p   	 	 	 G o s u b   M o v e R i g h t M 1 
 
 K e y   D o w n   	 	 G o s u b   M o v e L e f t M 1 
 
 K e y   P a g e u p 	 	 G o s u b   M o v e U p 
 
 K e y   P a g e d o w n 	 G o s u b   M o v e D o w n 
 
 
 
 ' G o s u b   D i s a b l e M o t o r 
 
 S t o p 
 
 
 
 
 
 
 
 '   = = = = = = = = = = = = = = =   H O M E   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   H o m e A l l 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 3 )   =   S l o t ( 3 )   +   3 0   	 	 ' d i s e n g a g e   M 1 
 
 	 S l o t ( 1 )   =   S l o t ( 1 )   +   3 0 	 	 ' d i s e n g a g e   M 0 
 
 	 G o s u b   H o m e _ X 
 
 	 G o s u b   H o m e _ Y 
 
 	 G o s u b   H o m e _ Z 
 
 	 G o s u b   W a i t A l l M o t o r s 
 
 	 ' G o s u b   D i s a b l e M o t o r 
 
 R e t u r n 
 
 '   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 
 
 '   = = = = = = = = = = = = = = =   H O M I N G   M O T O R   X   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   H o m e _ X 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 3 )   =   S l o t ( 3 )   +   3 0   	 	 ' d i s e n g a g e   M 1 
 
 	 S l o t ( 1 )   =   S l o t ( 1 )   +   3 0 	 	 ' d i s e n g a g e   M 0 
 
 	 L a b e l   H o m e _ X _ 1 
 
 	 	 S l o t ( 1 )   =   S l o t ( 1 )   -   0 . 4 	 	 '   d i r e c t i o n   a n d   s p e e d   g o t o   s w i t c h 
 
 	 	 W a i t   S e c o n d s   0 . 0 1 	 	 	 '   d o   n o t   a l t e r ,   l o o p   t i m e   0 . 0 2   S e c 
 
 	 	 I f   S l o t ( 7 )   >   5 0 0   	 	 	 '   l i m i t   s w i t c h 
 
 	 	 	 G o t o   H o m e _ X _ 2 
 
 	 	 E n d I f 
 
 	 	 G o t o   H o m e _ X _ 1 
 
 L a b e l   H o m e _ X _ 2 
 
 	 S l o t ( 1 )   =   S l o t ( 1 )   +   0 . 8 	 	 '   d i r e c t i o n   a n d   s p e e d   r e t u r n   f r o m   s w i t c h 
 
 	 W a i t   S e c o n d s   0 . 0 2 	 	 	 '   d o   n o t   a l t e r ,   l o o p   t i m e   0 . 0 2   S e c 
 
 	 I f   S l o t   ( 7 )   <   5 0 0 	 	 	 '   l i m i t   s w i t c h 
 
 	 	 G o t o   H o m e _ X _ 3 
 
 	 E n d I f 
 
 	 G o t o   H o m e _ X _ 2 
 
 L a b e l   H o m e _ X _ 3 
 
 	 S l o t   1   =   R e s e t 	 	 	 	 '   R e s e t   t h e   s l o t   v a l u e 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 	 S l o t   1   =   7 5 	 	 	 	 	 '   d e c l a r e d   s w i t c h   a n g l e 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 	 S l o t   1   =   1 8 0 	 	 	 	 	 '   m o v e   t o   t h i s   a n g l e 
 
 R e t u r n 
 
 '   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 
 
 '   = = = = = = = = = = = = = = =   H O M I N G   M O T O R   Y   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   H o m e _ Y 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 1 )   =   S l o t ( 1 )   +   3 0 	 ' d i s e n g a g e   M 0 
 
 	 S l o t ( 3 )   =   S l o t ( 3 )   +   3 0 	 ' d i s e n g a g e   M 1 
 
 	 L a b e l   H o m e _ Y _ 1 
 
 	 	 S l o t ( 3 )   =   S l o t ( 3 )   -   0 . 4 	 	 '   d i r e c t i o n   a n d   s p e e d   g o t o   s w i t c h 
 
 	 	 W a i t   S e c o n d s   0 . 0 1 	 	 	 '   d o   n o t   a l t e r ,   l o o p   t i m e   0 . 0 2   S e c 
 
 	 	 I f   S l o t ( 8 )   >   5 0 0   	 	 	 '   l i m i t   s w i t c h 
 
 	 	 	 G o t o   H o m e _ y _ 2 
 
 	 	 E n d I f 
 
 	 G o t o   H o m e _ Y _ 1 
 
 	 
 
 L a b e l   H o m e _ y _ 2 
 
 	 S l o t ( 3 )   =   S l o t ( 3 )   +   0 . 8         '   d i r e c t i o n   a n d   s p e e d   r e t u r n   f r o m   s w i t c h 
 
 	 W a i t   S e c o n d s   0 . 0 2 	 	 	 '   d o   n o t   a l t e r ,   l o o p   t i m e   0 . 0 2   S e c 
 
 	 I f   S l o t   ( 8 )   <   5 0 0 	 	 	 '   l i m i t   s w i t c h 
 
 	 	 G o t o   H o m e _ y _ 3 
 
 	 E n d I f 
 
 G o t o   H o m e _ y _ 2 
 
 
 
 L a b e l   H o m e _ y _ 3 
 
 	 S l o t   3   =   R e s e t 	 	 	 	 '   R e s e t   t h e   s l o t   v a l u e 
 
 	 W a i t   S e c o n d s   0 . 1 
 
 	 S l o t   3   =   3 0 	 	 	 	         '   D e c l a r e d   s w i t c h   a n g l e 
 
 	 W a i t   S e c o n d s   0 . 1 
 
 	 S l o t   3   =   1 8 0 	 	 	 	 '   m o v e   t o   t h i s   a n g l e 
 
 R e t u r n 
 
 '   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 
 
 '   = = = = = = = = = = = = = = =   H O M I N G   M O T O R   Z   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   H o m e _ Z 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 L a b e l   H o m e _ Z _ 1 
 
 	 	 S l o t ( 5 )   =   S l o t ( 5 )   +   1 	 	 '   d i r e c t i o n   a n d   s p e e d   g o t o   s w i t c h 
 
 	 	 W a i t   S e c o n d s   0 . 0 6 	 	 	 '   d o   n o t   a l t e r ,   l o o p   t i m e   0 . 0 2   S e c 
 
 	 	 I f   S l o t ( 9 )   >   5 0 0   	 	 	 '   l i m i t   s w i t c h 
 
 	 	 	 G o t o   H o m e _ Z _ 2 
 
 	 	 E n d I f 
 
 	 	 G o t o   H o m e _ Z _ 1 
 
 L a b e l   H o m e _ Z _ 2 
 
 	 S l o t ( 5 )   =   S l o t ( 5 )   -   0 . 5 	 '   d i r e c t i o n   a n d   s p e e d   r e t u r n   f r o m   s w i t c h 
 
 	 W a i t   S e c o n d s   0 . 0 6 	 	 	 '   d o   n o t   a l t e r ,   l o o p   t i m e   0 . 0 2   S e c 
 
 	 I f   S l o t   ( 9 )   <   5 0 0 	 	 	 '   l i m i t   s w i t c h 
 
 	 	 G o t o   H o m e _ Z _ 3 
 
 	 E n d I f 
 
 	 G o t o   H o m e _ Z _ 2 
 
 L a b e l   H o m e _ Z _ 3 
 
 	 S l o t   5   =   R e s e t 	 	 	 	 '   R e s e t   t h e   s l o t   v a l u e 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 	 S l o t   5   =   1 4 9   	 	 	 	 '   d e c l a r e d   i n i t i a l   p o s i t i o n 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 	 S l o t   5   =   1 3 5 	 	 	 	 '   m o v e   t o   s t a r t   p o s i t i o n 
 
 R e t u r n 
 
 '   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 L a b e l   M o v e R i g h t M 0 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 1 )   =   S l o t ( 1 )   -   1 
 
 R e t u r n 
 
 
 
 L a b e l   M o v e L e f t M 0 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 1 )   =   S l o t ( 1 )   +   1 
 
 R e t u r n 
 
 
 
 L a b e l   M o v e R i g h t M 1 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 3 )   =   S l o t ( 3 )   +   1 
 
 R e t u r n 
 
 
 
 L a b e l   M o v e L e f t M 1 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 3 )   =   S l o t ( 3 )   -   1 
 
 R e t u r n 
 
 
 
 L a b e l   M o v e U p 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 5 )   =   S l o t ( 5 )   +   1 
 
 R e t u r n 
 
 
 
 L a b e l   M o v e D o w n 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 S l o t ( 5 )   =   S l o t ( 5 )   -   1 
 
 R e t u r n 
 
 
 
 '   = = = = = = = = = = = = = = =   J O I S T I C K   M A N A G E M E N T   = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   J o y 
 
 	 G o s u b   E n a b l e M o t o r 
 
 	 v 1   =   S l o t ( 1 3 ) 
 
 	 I f   v 1   >   5 5 0   	 	 	 	 	 	 	 	 ' m o v e   t o   R i g h t   M 0 
 
 	 	 S l o t ( 1 )   =   S l o t ( 1 )   -   ( v 1   -   5 5 0 )   *   0 . 0 1   	 ' i n c r e m e n t a l   m o v e 
 
 	 E n d I f 
 
 	 I f   v 1   <   4 5 0 	 	 	 	 	 	 	 	 	 ' m o v e   t o   L e f t   M 0 
 
 	 	 S l o t ( 1 )   =   S l o t ( 1 )   +   ( 4 5 0   -   v 1 )   *   0 . 0 1 	 ' i n c r e m e n t a l   m o v e 
 
 	 E n d I f 
 
 	 v 2   =   S l o t ( 1 4 ) 
 
 	 I f   v 2   >   5 5 0   	 	 	 	 	 	 	 ' m o v e   t o   l e f t   M 1 
 
 	 	 S l o t ( 3 )   =   S l o t ( 3 )   -   ( v 2   -   5 5 0 )   *   0 . 0 1   	 ' i n c r e m e n t a l   m o v e 
 
 	 E n d I f 
 
 	 I f   v 2   <   4 5 0   	 	 	 	 	 	 	 ' m o v e   t o   r i g h t   M 1 
 
 	 	 S l o t ( 3 )   =   S l o t ( 3 )   +   ( 4 5 0   -   v 2 )   *   0 . 0 1 	 ' i n c r e m e n t a l   m o v e 
 
 	 E n d I f 
 
 	 v 3   =   S l o t ( 1 5 ) 
 
 	 I f   v 3   >   5 5 0   	 	       	 	 	 	 	 ' m o v e   t o   u p   M 2   ( Z ) 
 
 	 	 S l o t ( 5 )   =   S l o t ( 5 )   +   ( 4 5 0   -   v 3 )   *   0 . 0 0 1 	 ' i n c r e m e n t a l   m o v e 
 
 	 E n d I f 	   	 	 	 	 	 ' n o t a :   j o y   Z   v e r t i c a l e   d i f e t t o s o 
 
 	 I f   v 3   <   4 5 0   	 	 	 	 	 	 	 ' m o v e   t o   d o w n   M 2   ( Z ) 
 
 	 	 S l o t ( 5 )   =   S l o t ( 5 )   -   ( v 3   -   5 5 0 )   *   0 . 0 0 1   	 ' i n c r e m e n t a l   m o v e 
 
 	 E n d I f 
 
 	 I f   S l o t ( 2 3 )   <   5 5 0 
 
 	 	 S l o t ( 1 2 )   =   0 	 	 	 	 	 	 	 ' s t o p   p u m p 
 
 	 E l s e 
 
 	 	 S l o t ( 1 2 )   =   1 0 0 0 	 	 	 	 	 	 	 ' s t a r t   p u m p 
 
 	 E n d I f 
 
 	 I f   S l o t ( 2 6 )   >   5 0 0   	 	 	 	 	 	 	 ' B u t t o n   4   t o   e x i t   j o y   m o d e 
 
 	 	 R e t u r n 
 
 	 E n d I f 
 
 G o t o   J o y 
 
 R e t u r n 
 
 
 
 ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 ' - - - - -   s u b r o u t i n e   a r e a   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 
 '   = = = = = = = = = = = = = = =   E N A B L E   /   D I S A B L E   M O T O R S   = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   E n a b l e M o t o r 
 
 	 S l o t   1 1   =   1 0 0 0 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 R e t u r n 
 
 
 
 L a b e l   D i s a b l e M o t o r 
 
 	 S l o t   1 1   =   0 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 R e t u r n 
 
 
 
 '   = = = = = = = = = = = = = = =   E N A B L E   /   D I S A B L E   &   T E S T   P U M P   = = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   S t a r t P u m p 
 
 	 S l o t   1 2   =   1 0 0 0 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 R e t u r n 
 
 
 
 L a b e l   S t o p P u m p 
 
 	 S l o t   1 2   =   0 
 
 	 W a i t   S e c o n d s   0 . 0 5 
 
 R e t u r n 
 
 
 
 L a b e l   P u m p 
 
 	 G o s u b   S t a r t P u m p 
 
 	 W a i t   S e c o n d s   0 . 5 
 
 	 G o s u b   S t o p P u m p 
 
 R e t u r n 
 
 
 
 '   = = = = = = = = = = = = = = =   W   A   I   T       A   L   L       M   O   T   O   R   S   = = = = = = = = = = = = = = = = = = = = 
 
 L a b e l   W a i t A l l M o t o r s 
 
 '   - - - - - - - - - - - - - - - - - -   t h i s   W a i t   e n s u r e s   t h a t   t h e   m o t o r s   a r e   r e a l l y   s t a r t e d 
 
 	 W a i t   S e c o n d s   0 . 1 
 
 	 L a b e l   W a i t A l l M o t o r s 2 
 
 	 	 I f   A b s ( S l o t ( 2 ) )   <   0 . 0 1   A n d   A b s ( S l o t ( 4 ) )   <   0 . 0 1   A n d   A b s ( S l o t ( 6 ) )   <   0 . 0 1 
 
 	 	 	 R e t u r n 
 
 	 	 E n d I f 
 
 	 	 W a i t   S e c o n d s   0 . 0 1 
 
 	 G o t o   W a i t A l l M o t o r s 2 
 
 '   - - - - - - - - - - - - - - - - - -   t h i s   l i n e   i s   r e q u i r e d   t o   i n d e n t   c o r r e c t l y 
 
 G o t o   W a i t A l l M o t o r s 
 
 
 
 
 
 ' = = = = = =   D U M M Y   A R E A   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 ' = = = = = =   T O   D O   A R E A   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 
 
 
 
 ' = = = = = =   S E T   U P   A R E A   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 
 
 '   = = = = = = = = = = =   H A R D W A R E   S E T   U P   D V R 8 8 2 5   = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 
 
 '   M o t o r   M 0   c u r r e n t   2 0 0   m A 
 
 '   M i c r o s t e p   " A B C "   3 2   S p e e d   1 0 0 0 0   A c c   3 0 0   S t e p / m m   7 4 . 2       r e d u c t i o n   r a t i o       4 : 1 
 
 '   M o t o r   M 1   c u r r e n t   2 0 0   m A 
 
 '   M i c r o s t e p   " A B C "   3 2   S p e e d   1 0 0 0 0   A c c   3 0 0   S t e p / m m   7 4 . 2       r e d u c t i o n   r a t i o       4 : 1 
 
 '   M o t o r   Z   c u r r e n t   2 0 0   m A 
 
 '   M i c r o s t e p   "   B C "     8   S p e e d     1 0 0 0   A c c   1 0 0   S t e p   4 0 0               l 	 e a d s c r e w :   4 m m   f o r   o n e   t u r n 
 
 
 
 '   S t e p p e r D r i v e r   V 2   b o a r d   j u m p e r   s e t   u p   w i t h   D R V 8 8 2 5 : 
 
 '   M o t o r   M 0 :   A = i n s e r t         B = r e m o v e       C = I n s e r t       1 / 3 2   s t e p   6 4 0 0   s t e p / r u n 
 
 '   1         0   1 0 0 0   1 0 0   1 0 0 0 0   3 0 0     5 2 
 
 '   M o t o r   M 1 :   A = i n s e r t         B = r e m o v e       C = I n s e r t       1 / 3 2   s t e p   6 4 0 0   s t e p / r u n 
 
 '   3   1 0 0 0         0   1 0 0   1 0 0 0 0   3 0 0     5 2 
 
 '   M o t o r   M Z :   A = i n s e r t         B = i n s e r t       C = r e m o v e       1 / 4     s t e p     8 0 0   s t e p / r u n   c u r r e n t   2 0 0   m A 
 
 '   5   1 0 0 0         0   1 0 0     1 0 0 0   1 0 0   4 0 0 
 
 
 
 '   E N A B L E   s t e p p e r   m o t o r s   C 7 : 
 
 '   f r o m   c e n t e r   t o   O N   =   a l w a y s   o n 
 
 '   f r o m   c e n t e r   t o   O u t 2   =   S W   c o n t r o l l e d 
 
 '   G e a r   r a t i o   f o r   M 0   a n d   M 1   1 : 4       S t e p   x   m m   =   8 0 0   x   3 6 0   /   3 6 0   =   5 9 . 5 5 6   ? ? ? ? ? ? ? ? ? ? ? 
 
 '   L e a d s c r e w :   4 m m   f o r   o n e   t u r n 
 
 '   I n d u c t i v e   s e n s o r :   B l u e = G N D     B r o w n = + 5 V D C     B l a c k = o u t p u t 
 
 
 
 
 
 ' W A T C H   N e w   w a t c h 
 
 